package com.zzyl.controller.customer;

import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.CountTimesVo;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping()
public class ReservationController {
    @Autowired
    private ReservationService reservationService;
    @GetMapping("/customer/reservation/cancelled-count")
    @ApiOperation("查询预约数量")
    public ResponseResult selectReservate(){
        reservationService.selectReservate();
        return ResponseResult.success();
    }

    @GetMapping("/customer/reservation/countByTime")
    @ApiOperation("查询剩余预约数量")
    public ResponseResult checkRemainderNumber(@RequestParam Long time){

        List<CountTimesVo> lists =reservationService.checkRemainderNumber(time);
        return ResponseResult.success(lists);
    }
    @PostMapping("/customer/reservation")
    @ApiOperation("新增预约")
    public ResponseResult sava(@RequestBody ReservationDto reservationDto){
        reservationService.save(reservationDto);
        return  ResponseResult.success();
    }

    @GetMapping("/customer/reservation/page")
    @ApiOperation("分页查询")
    public ResponseResult selectByPage(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
             Integer status
    ){
        PageResponse<ReservationVo>lists= reservationService.selectByPage(pageNum,pageSize,status);
        return  ResponseResult.success(lists);
    }
    @PutMapping("/customer/reservation/{id}/cancel")
    public ResponseResult cancel(@PathVariable Long id){
        reservationService.cancel(id);
        return  ResponseResult.success();
    }
}
